package com.example.mygaode.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.CameraUpdate;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.LocationSource;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.UiSettings;
import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.amap.api.maps2d.model.CameraPosition;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.Marker;
import com.amap.api.maps2d.model.MarkerOptions;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeAddress;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import com.amap.api.services.route.BusRouteResult;
import com.amap.api.services.route.DrivePath;
import com.amap.api.services.route.DriveRouteResult;
import com.amap.api.services.route.RideRouteResult;
import com.amap.api.services.route.RouteSearch;
import com.amap.api.services.route.WalkRouteResult;
import com.example.mygaode.R;
import com.example.mygaode.lib.LocationTask;
import com.example.mygaode.lib.OnLocationGetListener;
import com.example.mygaode.lib.PositionEntity;
import com.example.mygaode.lib.RegeocodeTask;
import com.example.mygaode.lib.RouteTask;
import com.example.mygaode.route.DrivingRouteOverLay;
import com.example.mygaode.utils.AMapUtil;
import com.example.mygaode.utils.ToastUtil;
import com.example.mygaode.utils.Utils;
import com.example.mylibrarybase.utils.LogUtils;
import com.example.mylibrarybase.utils.UtilsToast;


public class MainActivity_ditutu extends Activity  implements AMap.OnCameraChangeListener,
        AMap.OnMapLoadedListener, OnLocationGetListener, View.OnClickListener,
        RouteTask.OnRouteCalculateListener ,AMapLocationListener, RouteSearch.OnRouteSearchListener, LocationSource, AMap.OnMapClickListener, AMap.OnMarkerClickListener, AMap.OnInfoWindowClickListener, AMap.InfoWindowAdapter {

    private MapView mMapView;

    private AMap mAmap;

    private TextView mAddressTextView;

    private Button mDestinationButton;

    private Marker mPositionMark;

    private LatLng mStartPosition;

    private RegeocodeTask mRegeocodeTask;

    private LinearLayout mDestinationContainer;

    private TextView mRouteCostText;

    private TextView mDesitinationText;

    private LocationTask mLocationTask;

    private ImageView mLocationImage;

    private LinearLayout mFromToContainer;

    private Button mCancelButton;

    private boolean mIsFirst = true;

    private boolean mIsRouteSuccess = false;
    LocationSource.OnLocationChangedListener mListener;
    private double mLongitude;
    private double mLatitude;
    private boolean tagg;
    private AMapLocationClient locationClient;
    /**
     * 定位监听
     */
    AMapLocationListener locationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation loc) {
            if (null != loc) {
                mLongitude = loc.getLongitude();
                mLatitude = loc.getLatitude();

                //解析定位结果
                String result = Utils.getLocationStr(loc);
                LogUtils.i("现在定位位置"+result);
                mListener.onLocationChanged(loc);// 显示系统小蓝点
                //tvReult.setText(result);
                //mAMap.animateCamera(CameraUpdateFactory.);
                if (tagg){
                    //移动到某个坐标
                    mAmap.animateCamera(CameraUpdateFactory.changeLatLng(new LatLng(
                            mLatitude,mLongitude)));
                    //移动到某个做表 并且设置 缩放级别
                    // mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng( mLatitude,mLongitude),mMaxZoomLevel -4));
                }
            } else {
                // tvReult.setText("定位失败，loc is null");
                UtilsToast.showToast(MainActivity_ditutu.this, "定位失败，loc is null" );
            }
        }
    };
    private UiSettings mUiSettings;
    private float mMaxZoomLevel;
    private float mMinZoomLevel;
    private RouteSearch mRouteSearch;
    private String keyWord = "";// 要输入的poi搜索关键字
    private ProgressDialog progDialog = null;// 搜索时进度条
    private EditText editCity;// 要输入的城市名字或者城市区号
    private PoiResult poiResult; // poi返回的结果
    private int currentPage = 0;// 当前页面，从0开始计数
    private PoiSearch.Query query;// Poi查询条件类
    private PoiSearch poiSearch;// POI搜索
    private DriveRouteResult mDriveRouteResult;
    private AMapLocationClientOption locationOption;
    private GeocodeSearch geocoderSearch;
    private String addressName;
    private LatLonPoint mLatLonPoint;
    private Marker regeoMarker;
    private EditText mEd_sousuo;

    @Override
    public void onLocationChanged(AMapLocation loc) {
        if (null != loc) {
            mLongitude = loc.getLongitude();
            mLatitude = loc.getLatitude();

            //解析定位结果
            String result = Utils.getLocationStr(loc);
            LogUtils.i("现在定位位置"+result);
            mListener.onLocationChanged(loc);// 显示系统小蓝点
            //tvReult.setText(result);
            //mAMap.animateCamera(CameraUpdateFactory.);
            if (tagg){
                //移动到某个坐标
                mAmap.animateCamera(CameraUpdateFactory.changeLatLng(new LatLng(
                        mLatitude, mLongitude)));
                //移动到某个做表 并且设置 缩放级别
                // mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng( mLatitude,mLongitude),mMaxZoomLevel -4));
            }
        } else {
            // tvReult.setText("定位失败，loc is null");
            UtilsToast.showToast(this, "定位失败，loc is null" );
        }
    }



    /**
     * 路线规划相关
     * @param busRouteResult
     * @param i
     */
    @Override
    public void onBusRouteSearched(BusRouteResult busRouteResult, int i) {

    }
    /**
     * 显示进度框
     */
    private void showProgressDialog() {
        if (progDialog == null)
            progDialog = new ProgressDialog(this);
        progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progDialog.setIndeterminate(false);
        progDialog.setCancelable(false);
        progDialog.setMessage("正在搜索:\n" + keyWord);
        progDialog.show();
    }

    /**
     * 隐藏进度框
     */
    private void dissmissProgressDialog() {
        if (progDialog != null) {
            progDialog.dismiss();
        }
    }
    /**
     * 路线规划结果 (重要)
     * @param result
     * @param errorCode
     */
    @Override
    public void onDriveRouteSearched(DriveRouteResult result, int errorCode) {
        dissmissProgressDialog();
        // 清理地图上的所有覆盖物
        mAmap.clear();
        if (errorCode == 1000) {
            if (result != null && result.getPaths() != null) {
                if (result.getPaths().size() > 0) {
                    //获取一个结果集
                    mDriveRouteResult = result;
                    //通过结果集获取道路信息 DrivePath
                    final DrivePath drivePath = mDriveRouteResult.getPaths()
                            .get(0);
                    DrivingRouteOverLay drivingRouteOverlay = new DrivingRouteOverLay(
                            this, mAmap, drivePath,
                            mDriveRouteResult.getStartPos(),
                            mDriveRouteResult.getTargetPos(), null);
                    drivingRouteOverlay.setNodeIconVisibility(false);//设置节点marker是否显示
                    drivingRouteOverlay.setIsColorfulline(true);//是否用颜色展示交通拥堵情况，默认true
                    drivingRouteOverlay.removeFromMap();
                    drivingRouteOverlay.addToMap();
                    drivingRouteOverlay.zoomToSpan();
                    // mBottomLayout.setVisibility(View.VISIBLE);
                    int dis = (int) drivePath.getDistance();
                    int dur = (int) drivePath.getDuration();
                    String des = AMapUtil.getFriendlyTime(dur)+"("+AMapUtil.getFriendlyLength(dis)+")";
                    LogUtils.i("路线规划时间"+des);

                    // mRotueTimeDes.setText(des);
                    // mRouteDetailDes.setVisibility(View.VISIBLE);
                    int taxiCost = (int) mDriveRouteResult.getTaxiCost();
                    LogUtils.i("路线规划打车大约"+taxiCost);

                    LogUtils.i("统计规划路线的数据为"+"\n"+"路线规划时间"+des+"\n"+"路线规划打车大约"+taxiCost+"\n");
                    UtilsToast.showToast(this,"统计规划路线的数据为"+"\n"+"路线规划时间"+des+"\n"+"路线规划费用大约是"+taxiCost+"\n" );
                    //   mRouteDetailDes.setText("打车约"+taxiCost+"元");
                    //  mBottomLayout.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            Intent intent = new Intent(mContext,
//                                    DriveRouteDetailActivity.class);
//                            intent.putExtra("drive_path", drivePath);
//                            intent.putExtra("drive_result",
//                                    mDriveRouteResult);
//                            startActivity(intent);
//                        }
//                    });
                } else if (result != null && result.getPaths() == null) {
                    ToastUtil.show(this, "没收到相关数据");
                }

            } else {
                ToastUtil.show(this, "没收到相关数据");
            }
        } else {
            ToastUtil.showerror(this.getApplicationContext(), errorCode);
        }
    }

    /**
     * 路线规划相关
     * @param walkRouteResult
     * @param i
     */
    @Override
    public void onWalkRouteSearched(WalkRouteResult walkRouteResult, int i) {

    }

    /**
     * 路线规划相关
     * @param rideRouteResult
     * @param i
     */
    @Override
    public void onRideRouteSearched(RideRouteResult rideRouteResult, int i) {

    }

    /**
     * 激活定位
     */
    @Override
    public void activate(OnLocationChangedListener listener) {
        mListener = listener;
        if (locationClient == null) {
            locationClient = new AMapLocationClient(this);
            locationOption = new AMapLocationClientOption();
            //设置定位监听
            locationClient.setLocationListener(this);
            //设置为高精度定位模式
            locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
            //设置定位参数
            locationClient.setLocationOption(locationOption);
            // 此方法为每隔固定时间会发起一次定位请求，为了减少电量消耗或网络流量消耗，
            // 注意设置合适的定位时间的间隔（最小间隔支持为2000ms），并且在合适时间调用stopLocation()方法来取消定位请求
            // 在定位结束后，在合适的生命周期调用onDestroy()方法
            // 在单次定位情况下，定位无论成功与否，都无需调用stopLocation()方法移除请求，定位sdk内部会移除
            locationClient.startLocation();
        }
    }
    @Override
    public void deactivate() {

    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_ditutu);
        init(savedInstanceState);
        mLocationTask = LocationTask.getInstance(getApplicationContext());
        mLocationTask.setOnLocationGetListener(this);
        mRegeocodeTask = new RegeocodeTask(getApplicationContext());
        RouteTask.getInstance(getApplicationContext())
                .addRouteCalculateListener(this);
        mUiSettings = mAmap.getUiSettings();

        regeoMarker = mAmap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
                .icon(BitmapDescriptorFactory
                        .defaultMarker(BitmapDescriptorFactory.HUE_RED)));
        //注册监听
        registerListener();
        //初始化页面上的view 包括高德地图
        initView();
        //初始化定位
        initLocation();
    }

    private void initView() {
        mEd_sousuo = (EditText) findViewById(R.id.ed_sousuo);
        //mEd_sousuo.addTextChangedListener(this);

        TextView tv_sousuo = (TextView) findViewById(R.id.tv_sousuo);
        TextView tv_cler = (TextView) findViewById(R.id.tv_cler);
        TextView tv_guihua = (TextView) findViewById(R.id.tv_guihua);
        TextView tv_loacatme = (TextView) findViewById(R.id.tv_loacatme);
        TextView start_locsh = (TextView) findViewById(R.id.start_locsh);
        TextView stop_locsh = (TextView) findViewById(R.id.stop_locsh);
    }

    /**
     * 注册监听
     */
    private void registerListener() {
        mAmap.setOnMapClickListener(this);
        mAmap.setOnMarkerClickListener(this);
        mAmap.setOnInfoWindowClickListener(this);
        mAmap.setInfoWindowAdapter(this);

    }
    private void init(Bundle savedInstanceState) {

        mAddressTextView = (TextView) findViewById(R.id.address_text);
        mDestinationButton = (Button) findViewById(R.id.destination_button);
        mDestinationButton.setOnClickListener(this);
        mMapView = (MapView) findViewById(R.id.map);
        mMapView.onCreate(savedInstanceState);
        mAmap = mMapView.getMap();
        mAmap.getUiSettings().setZoomControlsEnabled(false);
        mAmap.setOnMapLoadedListener(this);
        mAmap.setOnCameraChangeListener(this);

        mDestinationContainer = (LinearLayout) findViewById(R.id.destination_container);
        mRouteCostText = (TextView) findViewById(R.id.routecost_text);
        mDesitinationText = (TextView) findViewById(R.id.destination_text);
        mDesitinationText.setOnClickListener(this);
        mLocationImage = (ImageView) findViewById(R.id.location_image);
        mLocationImage.setOnClickListener(this);
        mFromToContainer = (LinearLayout) findViewById(R.id.fromto_container);
        mCancelButton = (Button) findViewById(R.id.cancel_button);
      //  mFromToContainer.setVisibility(View.VISIBLE);
    }
    /**
     * 当地图被点击了的回调
     * @param latLng 包含 坐标消息的
     */
    @Override
    public void onMapClick(LatLng latLng) {
        //设定终点 并且 把坐标点传给 工具类 翻译成 具体资料信息
        showCoderSearch(setEndPoint(latLng));

    }

    /**
     * 通过 坐标点 翻译成  具体地方中文的
     */
    private void showCoderSearch(final LatLonPoint mLatLonPoint) {
        geocoderSearch = new GeocodeSearch(this);

        geocoderSearch.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() {
            @Override
            public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
                RegeocodeAddress regeocodeAddress = result.getRegeocodeAddress();
                String formatAddress = regeocodeAddress.getFormatAddress();
                LogUtils.i("点击位置的数据"+formatAddress);
                if (rCode == 1000) {
                    if (result != null && result.getRegeocodeAddress() != null
                            && result.getRegeocodeAddress().getFormatAddress() != null) {

                        //终点文字信息
                        addressName = result.getRegeocodeAddress().getFormatAddress()
                                + "附近";
                        LogUtils.i("点击地图的点的数据"+ addressName);
                        //移动到这个点 设定缩放范围
                        mAmap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                                AMapUtil.convertToLatLng(mLatLonPoint), 15));
                        //设定一个号 给这个 覆盖物
                        regeoMarker.setPosition(AMapUtil.convertToLatLng(mLatLonPoint));

                        //ed_end.setText(addressName);

                        ToastUtil.show(MainActivity_ditutu.this, addressName);
                    } else {
                        ToastUtil.show(MainActivity_ditutu.this, "没有数据");
                    }
                } else {
                    ToastUtil.showerror(MainActivity_ditutu.this, rCode);
                }
            }

            @Override
            public void onGeocodeSearched(GeocodeResult result, int rCode) {
            }
        });
        //通过终点 来设定终点 坐标
        RegeocodeQuery query = new RegeocodeQuery(mLatLonPoint, 200,GeocodeSearch.AMAP);
        geocoderSearch.getFromLocationAsyn(query);
    }

    /**
     * 当覆盖物被点击了
     * @param marker
     * @return
     */
    @Override
    public boolean onMarkerClick(Marker marker) {
        //marker.getId()
        String id = marker.getId();
        String snippet = marker.getSnippet();

        LogUtils.i("覆盖物marker"+marker.getTitle());
        LatLng latLng = marker.getPosition();
        LogUtils.i("内容是"+marker.getTitle()+id+snippet);
        UtilsToast.showToast(this, "内容是"+marker.getTitle()+snippet);
        setEndPoint(latLng);

        return true;
    }

    /**
     * 设定终点
     * @param latLng
     */
    private LatLonPoint setEndPoint(LatLng latLng) {
        double latitude = latLng.latitude;
        double longitude = latLng.longitude;
        LogUtils.i("点击的点的经纬度"+"latitude"+latitude+"\n"+"longitude"+longitude);
        mLatLonPoint = new LatLonPoint(latitude, longitude);
        return mLatLonPoint;
    }

    /**
     * 信息窗口被点击了
     * @param marker
     */
    @Override
    public void onInfoWindowClick(Marker marker) {

    }

    /**
     * 返回覆盖物
     * @param marker
     * @return
     */
    @Override
    public View getInfoWindow(Marker marker) {
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }


    public interface OnGetLocationListener {
        public void getLocation(String locationAddress);
    }
    private void hideView() {

        mFromToContainer.setVisibility(View.GONE);
        mDestinationButton.setVisibility(View.GONE);
        mCancelButton.setVisibility(View.GONE);
    }
    /**
     * 初始化定位
     *
     * @since 2.8.0
     * @author hongming.wang
     *
     */
    private void initLocation(){
        //初始化client
        locationClient = new AMapLocationClient(this.getApplicationContext());
        //设置定位参数
        locationClient.setLocationOption(getDefaultOption());
        // 设置定位监听
        locationClient.setLocationListener(locationListener);
        // 设置定位监听
        mAmap.setLocationSource(this);
        // 是否显示默认的定位按钮
        mUiSettings.setMyLocationButtonEnabled(true);
        // 是否可触发定位并显示定位层
        mAmap.setMyLocationEnabled(true);
        //获取最大级别
        mMaxZoomLevel = mAmap.getMaxZoomLevel();
        //获取最小级别
        mMinZoomLevel = mAmap.getMinZoomLevel();
        LogUtils.i("缩放级别"+"maxZoomLevel"+ mMaxZoomLevel +"\n"+"minZoomLevel"+ mMinZoomLevel);
        //设定初始化缩放级别
        mAmap.moveCamera(CameraUpdateFactory.zoomTo(mMaxZoomLevel -4));
        // mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lp.getLatitude(), lp.getLongitude()), 20));
        //路径规划
        mRouteSearch = new RouteSearch(this);
        //路径规划 回调
        mRouteSearch.setRouteSearchListener(this);
    }
    /**
     * 默认的定位参数
     * @since 2.8.0
     * @author hongming.wang
     *
     */
    private AMapLocationClientOption getDefaultOption(){
        LogUtils.i("默认的定位参数");
        AMapLocationClientOption mOption = new AMapLocationClientOption();
        mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选，设置定位模式，可选的模式有高精度、仅设备、仅网络。默认为高精度模式
        mOption.setGpsFirst(false);//可选，设置是否gps优先，只在高精度模式下有效。默认关闭
        mOption.setHttpTimeOut(30000);//可选，设置网络请求超时时间。默认为30秒。在仅设备模式下无效
        mOption.setInterval(5000);//可选，设置定位间隔。默认为2秒
        mOption.setNeedAddress(true);//可选，设置是否返回逆地理地址信息。默认是ture
        mOption.setOnceLocation(false);//可选，设置是否单次定位。默认是false
        mOption.setOnceLocationLatest(false);//可选，设置是否等待wifi刷新，默认为false.如果设置为true,会自动变为单次定位，持续定位时不要使用
        AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);//可选， 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
        return mOption;
    }
    private void showView() {
        mFromToContainer.setVisibility(View.VISIBLE);
        mDestinationButton.setVisibility(View.VISIBLE);
        if (mIsRouteSuccess) {
            mCancelButton.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onCameraChange(CameraPosition arg0) {
        hideView();
    }

    @Override
    public void onCameraChangeFinish(CameraPosition cameraPosition) {
        showView();
//        mStartPosition = cameraPosition.target;
//        mRegeocodeTask.setOnLocationGetListener(this);
//        mRegeocodeTask
//                .search(mStartPosition.latitude, mStartPosition.longitude);
//        if (mIsFirst) {
//            Utils.addEmulateData(mAmap, mStartPosition);
//            if (mPositionMark != null) {
//                // mPositionMark.setToTop();
//            }
//            mIsFirst = false;
//        }
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onPause() {
        super.onPause();
        mMapView.onPause();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mMapView.onSaveInstanceState(outState);
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
        mLocationTask.onDestroy();
    }

    @Override
    public void onMapLoaded() {

//        MarkerOptions markerOptions = new MarkerOptions();
//        // markerOptions.setFlat(true);
//        markerOptions.anchor(0.5f, 0.5f);
//        markerOptions.position(new LatLng(0, 0));
//        markerOptions
//                .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
//                        .decodeResource(getResources(),
//                                R.drawable.icon_loaction_start)));
//        mPositionMark = mAmap.addMarker(markerOptions);
//
//        mPositionMark.setPositionByPixels(mMapView.getWidth() / 2,
//                mMapView.getHeight() / 2);
        mLocationTask.startSingleLocate();
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.destination_button) {
            Intent intent = new Intent(this, DestinationActivity.class);
            startActivity(intent);

        } else if (i == R.id.location_image) {
            mLocationTask.startSingleLocate();

        } else if (i == R.id.destination_text) {
            Intent destinationIntent = new Intent(this,
                    DestinationActivity.class);
            startActivity(destinationIntent);

        }
    }

    @Override
    public void onLocationGet(PositionEntity entity) {
        // todo 这里在网络定位时可以减少一个逆地理编码
        mAddressTextView.setText(entity.address);
        RouteTask.getInstance(getApplicationContext()).setStartPoint(entity);

        mStartPosition = new LatLng(entity.latitue, entity.longitude);
        CameraUpdate cameraUpate = CameraUpdateFactory.newLatLngZoom(
                mStartPosition, mAmap.getCameraPosition().zoom);
        mAmap.animateCamera(cameraUpate);

    }

    @Override
    public void onRegecodeGet(PositionEntity entity) {
        mAddressTextView.setText(entity.address);
        entity.latitue = mStartPosition.latitude;
        entity.longitude = mStartPosition.longitude;
        RouteTask.getInstance(getApplicationContext()).setStartPoint(entity);
        RouteTask.getInstance(getApplicationContext()).search();
    }

    @Override
    public void onRouteCalculate(float cost, float distance, int duration) {
        mDestinationContainer.setVisibility(View.VISIBLE);
        mIsRouteSuccess = true;
        mRouteCostText.setVisibility(View.VISIBLE);
        mDesitinationText.setText(RouteTask
                .getInstance(getApplicationContext()).getEndPoint().address);
        mRouteCostText.setText(String.format("预估费用%.2f元，距离%.1fkm,用时%d分", cost,
                distance, duration));
        mDestinationButton.setText("我要用车");
        mCancelButton.setVisibility(View.VISIBLE);
        mDestinationButton.setOnClickListener(null);
    }
}
